<!DOCTYPE html>
<html lang="en">

<head>
    <head/>
    <title>预约挂号</title>
    <titleType style="display: none;">yygh</titleType>
    <link rel="stylesheet" href="/static/css/qyjm/page.css" />
    <%- include('./_global/appendJs') %>

</head>
<style>
    body {
        background: #fbfafa;
    }

    .filtrate-box li {
        border-bottom: 1px solid #DDDDDD;
    }

    .yygh-box .filtrate-sub-check {
        top: 3.625rem;
    }

    .search input {
        width: 94%;
        height: 2.4rem;
        border-radius: 5px;
        border: none;
        background: #f1f1f1;
        margin: .5rem 3%;
        font-size: 1.2rem;
        text-indent: .2rem;
        text-align: center;
    }

    .search input:focus {
        outline: none;
    }
</style>

<body>
    <!-- <header class="header-box grey fixed">
        <div class="header-content">
            <div class="left-tool">
                <a class="back" href="javascript:void(0);">
                    <i class="iconfont icon-back"></i>
                </a>
            </div>
            <div class="title">预约挂号</div>
        </div>
    </header> -->
    <section class="page-wrap yygh-box">
        <div class="search">
            <form action="javascript:;">
                <input placeholder="搜索医院" type="search" id="queryInput">
            </form>

        </div>

        <div class="doctor-list-box" id="hosDiv" style="margin-top:0;">
            <ul id="hosUl">
            </ul>
        </div>
    </section>
</body>
<script src="/static/lib/forweb.js"></script>
<script src="/quickJs/scripts/swiper/3.4.2/js/swiper.min.js"></script>
<script src="/static/js/<%=type%>/pageUrl.js"></script>
<script src="/static/js/<%=type%>/yygh.js"></script>
<script type="text/html" id="xzqhLi">
    <li>
        <a href="javascript:void(0);">离我最近</a>
    </li>
</script>
<script type="text/html" id="hosLi">
    <li>
        <a href="javascript:void(0);">
            <i class="hospital-icon hosImgUrl" style="height: 3.806rem;margin-top: 1rem;width: 5.075rem;"></i>
            <div class="text-box">
                <p>
                    <span class="title-text hosName" style="width:12.0rem"></span>
                    <span class="yellow-text hosLevel" style="
                                border: 1px solid #f89e00;
                                border-radius: 18px;
                                padding: 0px 5px 0px 5px;
                                margin-left: 0px;"></span>

                </p>
                <p>
                    <span class="doctorCount"></span>

                </p>
                <p>
                    <span class="telPhone"></span>

                </p>
            </div>
            <div class="item-after">
                <i class="iconfont icon-more"></i>
            </div>
        </a>
    </li>
</script>
<script type="text/javascript">
    




    function toKslb(hos) {
        var hosInfo = JSON.parse(hos.replace(/\s/g, ""));
        var requestFrom = $.QuickUrlUtils.getRequest("from");
        if (requestFrom == "treatment") {
            StoreCache.setCache("YYGH_HOSINFO", hosInfo)
            $.QuickUrlUtils.reBackAndRefreshJSBridge("*");
        } else {
            $.pageSwitch.goToUrl("myOrder", "hosDetail", "hosCode=" + hosInfo["hosCode"]);
        }
    }


    var page_yygh = (function ($, page_yygh) {


        /**加载视图*/
        function initView() {
            
            /**排序按钮*/
            $("#order").attr("value", "0");
            $("#order").on("click", function () {
                $(this).parents("li").siblings().find(".filtrate-sub-check").hide();
                $("#orderChildren").toggle();
                return false;
            });

            /**排序选中*/
            $("#orderChildren").on("click", "li", function () {
                if (!$(this).hasClass("active")) {
                    $(this).siblings("li").removeClass("active");
                    $(this).addClass("active");
                    $(this).parents(".filtrate-sub-check").hide();
                    var order = null;
                    var val = $(this).attr("value");
                    $("#order").attr("value", val).html($(this).find("a").html() +
                        "<i class='iconfont icon-more'></i>")
                    /**获取行政区划*/
                    var xzqh = $("#xzqh").attr("value");
                    var params = {};
                    if (xzqh != "0") {
                        params["districtCode"] = xzqh;
                    }
                    if (val != "0") {
                        params["sortType"] = val;
                    }
                    page_yygh.initHosInfo(params);
                }
            })

            // 点击document让当前的ul隐藏
            $(document).on("click", function () {
                $("#orderChildren").hide();
                $("#xzqhChildren").hide();
            })
            $("#orderChildren").on("click", function () {
                return false;
            });
            $("#xzqhChildren").on("click", function () {
                return false;
            });

            /**行政区划按钮*/
            $("#xzqh").attr("value", "0");
            $("#xzqh").on("click", function () {
                $(this).parents("li").siblings().find(".filtrate-sub-check").hide();
                $("#xzqhChildren").toggle();
                return false;
            });

            /**行政区划选中*/
            $("#xzqhChildren").on("click", "li", function () {
                if (!$(this).hasClass("active")) {
                    $(this).siblings("li").removeClass("active");
                    $(this).addClass("active");
                    $(this).parents(".filtrate-sub-check").hide();
                    var val = $(this).attr("value");
                    $("#xzqh").attr("value", val).html($(this).find("a").html() +
                        "<i class='iconfont icon-more'></i>")
                    /**加载医院信息*/
                    var params = {};
                    var order = $("#order").attr("value");
                    if (order != "0") {
                        params["sortType"] = order;
                    }
                    if (val != "0") {
                        params["districtCode"] = val;
                    }
                    page_yygh.initHosInfo(params);
                }
            })

            /**注册回调方法*/
            // $.JkcsUtils.jsbridgeRegister("search", callBack);
        }

        /**加载数据*/
        function initData() {
            /**加载医院信息*/
            var params = {};
            page_yygh.initHosInfo(params);
        }

        /**加载医院信息*/
        function initHosInfo(params) {
            /**获取用户经纬度有延迟，需要回调获取*/
            if (params["sortType"] == "1") {
                params["mapType"] = "AMap";
                $.JkcsUtils.nativePermission({
                    "type": "location",
                    "callBackMethod": "callBack",
                    "params": params
                });
                //			params["userLocation"] = $.JkcsUtils.getUserLocation("callBack",params);
            } else {
                page_yygh.callBack(params);
            }
        }

        function callBack(params) {
            params["pageSize"] = 10;
            //params["userLocation"] = params["longitude"]+","+params["latitude"];
            // params = {
            //     "districtCode": "",
            //     "hoscode": "",
            //     "hosname": "",
            //     "pageNum": 1,
            //     "pageSize": 10
            // }
            $("#hosUl").remove();
            var hosUl = $("<ul>").attr({
                "id": "hosUl"
            });
            $("#hosDiv").append(hosUl);
            layui.use('flow', function () {
                var flow = layui.flow;
                flow.load({
                    elem: '#hosUl' //指定列表容器
                        ,
                    end: " ",
                    done: function (page, next) { //到达临界点（默认滚动触发），触发下一页
                        params["pageNum"] = page;
                        // $.QuickRemote.AjaxJson({
                        //     funcName:"/api/yyghAdapter/getHospital"
                        //     ,callback:page_yygh.hospitalListHandler
                        //     ,params:params
                        //     ,additionParams:{next: next, page:page}
                        // });
                        $.ajax({
                            type: "POST", // 使用get方法访问后台
                            dataType: "json", // 返回json格式的数据
                            "headers": {
                                "Content-Type": "application/json",
                                "Cache-Control": "no-cache",
                            },
                            url: "/api/yyghAdapter/getHospital.service", // 要访问的后台地址
                            data: JSON.stringify(params), // 要发送的数据
                            success: function (data) {
                                if (data.code == "SUCCESS") {
                                    page_yygh.hospitalListHandler(data, {
                                        next: next,
                                        page: page
                                    });
                                } else {
                                    $.QuickAlert.alertFail({
                                        content: data.message
                                    });
                                }
                            }
                        });

                    }
                });
            });
        }

        function hospitalListHandler(result, obj) {
            var type = "";
            $("#orderChildren").find("li").each(function () {
                if ($(this).hasClass("active")) {
                    type = $(this).attr("value");
                    return;
                }
            });
            result = result.data;
            var pages = result["pageCount"];
            var ary = result["hospitals"];
            var lis = [];
            $(ary).each(function (index, item) {
                var value = item["distance"];
                if (value == "" || value == null) {
                    value = "0";
                }
                var hosLi = $($("#hosLi").html());
                if (type != "1") {
                    $(hosLi).find(".distance").remove();
                }
                //$(hosLi).find(".hosImgUrl").css("background","url(\"/static/images/hospital1.png\") no-repeat");
                $(hosLi).find(".hosName").text(item["hosName"]);
                $(hosLi).find(".hosLevel").text(page_yygh.getHosGrade(item["hosGrade"]) + page_yygh.getHosLevel(
                    item["hosLevel"])); //hosLevel
                /* $(hosLi).find(".isMedicare").text(page_yygh.getIsMedicare(item["isMedicare"]));*/
                $(hosLi).find(".doctorCount").text("地址：" + item["hosAddress"]);
                $(hosLi).find(".telPhone").text("电话：" + item["lxdh"] ? item["lxdh"] : "");
                var hosInfo = item;
                hosInfo.hosDesc = "";
                $(hosLi).find("a").attr("onclick", "toKslb('" + JSON.stringify(hosInfo) + "')");
                lis.push($(hosLi).prop("outerHTML"));
            });
            obj.next(lis.join(''), obj.page < pages);
        }

        /**获取医院等级*/
        function getHosLevel(hosLevel) {
            var value = "";
            if (hosLevel == "0") {
                value = "特等";
            } else if (hosLevel == "1") {
                value = "甲等";
            } else if (hosLevel == "2") {
                value = "乙等";
            } else if (hosLevel == "3") {
                value = "丙等";
            }
            return value;
        }

        /**判断是否是医保*/
        function getIsMedicare(medicare) {
            var value = "";
            if (medicare == "0") {
                value = "医保";
            } else //if(medicare == "1")
            {
                value = "非医保";
            }
            return value;
        }

        /**获取医院级别*/
        function getHosGrade(hosGrade) {
            var value = "";
            if (hosGrade == "0") {
                value = "社区卫生服务中心";
            } else if (hosGrade == "1") {
                value = "一级";
            } else if (hosGrade == "2") {
                value = "二级";
            } else if (hosGrade == "3") {
                value = "三级";
            } else if (hosGrade == "") {
                value = "未评级";
            }
            return value;
        }

        function queryByCondition() {

            $("#queryInput").blur();
            var params = {
                hosname: $("#queryInput").val(),
                pageNum: '1',
                pageSize: '10'
            }
            var api = '';
            page_yygh.initHosInfo(params, api);
        }

        var cfg_def = {
            initView: initView,
            initData: initData,
            initHosInfo: initHosInfo,
            callBack: callBack,
            hospitalListHandler: hospitalListHandler,
            getHosLevel: getHosLevel,
            getIsMedicare: getIsMedicare,
            getHosGrade: getHosGrade,
            queryByCondition: queryByCondition,

        }

        page_yygh.init = function (cfg) {
            $.extend(page_yygh, cfg_def, cfg);
            page_yygh.initData();
            page_yygh.initView();

            $('form').on('submit', page_yygh.queryByCondition)


        }

        return page_yygh;
    })(jQuery, {});
</script>


</html>